package com.zhf.servlet.class1;

import com.zhf.entity.Class1;
import com.zhf.service.ClassService;
import com.zhf.service.impl.ClassServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "ClassFIndServlet", urlPatterns = "/classFind")
public class ClassFIndServlet extends HttpServlet {
    ClassService classService = new ClassServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String className = request.getParameter("queryCode");
        String grade = request.getParameter("queryName");
        List<Class1> class1List = classService.queryClassByClassNameAndGrade(className, grade);
        if(class1List == null) class1List = new ArrayList<>();
        request.setAttribute("class1List", class1List);
        request.setAttribute("displayPageComponent", "none");
        request.getRequestDispatcher("Classindex.jsp").forward(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
